<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>编辑志愿者信息</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            line-height: 1.6;
            margin: 0;
            padding: 20px;
            background-color: #f5f5f5;
            color: #333;
        }

        .container {
            max-width: 800px;
            margin: 0 auto;
            background: #fff;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
        }

        h2 {
            color: #2c3e50;
            border-bottom: 2px solid #3498db;
            padding-bottom: 10px;
            margin-top: 0;
        }

        .form-group {
            margin-bottom: 20px;
        }

        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
            color: #555;
        }

        input[type="text"],
        input[type="file"],
        select {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }

        .avatar-container {
            display: flex;
            align-items: center;
            margin-bottom: 20px;
        }

        .avatar-img {
            width: 80px;
            height: 80px;
            border-radius: 50%;
            object-fit: cover;
            margin-right: 20px;
            border: 2px solid #3498db;
        }

        .no-avatar {
            color: #777;
            font-style: italic;
        }

        .btn {
            display: inline-block;
            padding: 10px 20px;
            background-color: #3498db;
            color: white;
            text-decoration: none;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            transition: background-color 0.3s;
        }

        .btn-submit {
            background-color: #2ecc71;
        }

        .btn-back {
            background-color: #95a5a6;
        }

        .btn:hover {
            opacity: 0.9;
        }

        .btn-submit:hover {
            background-color: #27ae60;
        }

        .btn-back:hover {
            background-color: #7f8c8d;
        }

        .btn-group {
            margin-top: 30px;
            display: flex;
            gap: 10px;
        }

        .checkbox-group {
            margin: 15px 0;
        }

        .checkbox-group input {
            margin-right: 10px;
        }
    </style>
    <script>
        function previewImage(input) {
            const preview = document.getElementById('preview');
            const noAvatarText = document.getElementById('noAvatarText');

            if (input.files && input.files[0]) {
                const reader = new FileReader();

                reader.onload = function(e) {
                    preview.src = e.target.result;
                    preview.style.display = 'block';
                    if (noAvatarText) {
                        noAvatarText.style.display = 'none';
                    }
                }

                reader.readAsDataURL(input.files[0]);
            }
        }
    </script>
</head>
<body>
<div class="container">
    <h2>编辑志愿者信息</h2>
    <form action="${pageContext.request.contextPath}/volunteer/edit" method="post" enctype="multipart/form-data">
        <input type="hidden" name="volunteer_id" value="${volunteer.volunteer_id}">
        <input type="hidden" name="userid" value="${volunteer.users.userid}">

        <div class="avatar-container">
            <c:choose>
                <c:when test="${not empty volunteer.url}">
                    <img id="preview" class="avatar-img" src="${volunteer.url}" alt="当前头像">
                </c:when>
                <c:otherwise>
                    <img id="preview" class="avatar-img" style="display:none;">
                    <p id="noAvatarText" class="no-avatar">暂无头像</p>
                </c:otherwise>
            </c:choose>
            <div>
                <div class="form-group">
                    <label for="avatar">上传新头像</label>
                    <input type="file" id="avatar" name="avatar" onchange="previewImage(this)">
                </div>
                <c:if test="${not empty volunteer.url}">
                    <div class="checkbox-group">
                        <input type="checkbox" name="deleteAvatar" id="deleteAvatar">
                        <label for="deleteAvatar" style="display: inline; font-weight: normal;">删除当前头像</label>
                    </div>
                </c:if>
            </div>
        </div>

        <div class="form-group">
            <label for="name">名字</label>
            <input type="text" id="name" name="name" value="${volunteer.name}">
        </div>

        <div class="form-group">
            <label for="sex">性别</label>
            <select id="sex" name="sex">
                <option value="男" ${volunteer.sex == '男' ? 'selected' : ''}>男</option>
                <option value="女" ${volunteer.sex == '女' ? 'selected' : ''}>女</option>
            </select>
        </div>

        <div class="form-group">
            <label for="birthdate">生日</label>
            <input type="text" id="birthdate" name="birthdate" value="${volunteer.birthdate}">
        </div>

        <div class="form-group">
            <label for="profession">职业</label>
            <input type="text" id="profession" name="profession" value="${volunteer.profession}">
        </div>

        <div class="form-group">
            <label for="skills">技能</label>
            <input type="text" id="skills" name="skills" value="${volunteer.skills}">
        </div>

        <div class="form-group">
            <label for="experience">经历</label>
            <input type="text" id="experience" name="experience" value="${volunteer.experience}">
        </div>

        <div class="form-group">
            <label for="phone">电话</label>
            <input type="text" id="phone" name="phone" value="${volunteer.phone}">
        </div>

        <div class="form-group">
            <label for="servicehours">服务时长</label>
            <input type="text" id="servicehours" name="servicehours" value="${volunteer.servicehours}">
        </div>

        <div class="btn-group">
            <input type="submit" class="btn btn-submit" value="提交">
            <a href="${pageContext.request.contextPath}/volunteer/list" class="btn btn-back">返回</a>
        </div>
    </form>
</div>
</body>
</html>